package com.minsf.rpc.protocol;

import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @Description 协议消息状态枚举
 * @Author minify
 * @Date 2024/3/29 21:04
 * @Project sf-rpc
 */
@Getter
@AllArgsConstructor
public enum ProtocolMessageStatusEnum {


    OK(200, "OK"),
    BAD_REQUEST(40, "badRequest"),
    BAD_RESPONSE(50, "badResponse");

    private final int value;

    private final String text;

    /**
     * 通过 value 获取枚举
     */
    public static ProtocolMessageStatusEnum getEnumByValue(int value) {

        ProtocolMessageStatusEnum[] values = values();
        for (ProtocolMessageStatusEnum protocolMessageStatusEnum : values) {
            if (ObjectUtil.equal(value, protocolMessageStatusEnum.value)) {
                return protocolMessageStatusEnum;
            }
        }
        return null;
    }

}
